package game.views;

import game.modes.PK1V1Mode;
import game.modes.Mode;
import game.modes.PracticeArenaMode;
import game.modes.ModeManage;
import hx.utils.SceneManager;
import game.worlds.GameWorld;
import hx.display.UILoadScene;

/**
 * 模式选择界面
 */
@:build(hx.macro.UIBuilder.build("assets/views/SelectModeView.xml"))
class SelectModeView extends UILoadScene {
	override function onLoaded() {
		super.onLoaded();
		this.close.clickEvent = this.releaseScene;
		this.btn_pvp1.clickEvent = () -> {
			var view = new RoleSelectView();
			view.selected2pEnabled = false;
			view.onRoleSelected = (roles:Array<Dynamic>) -> {
				trace("已选择了角色", roles);
				var gameWorld = new GameWorld({
					roles: [
						{
							id: roles[0].roleid,
							loadType: roles[0].abn == "1" ? ABN_DATA : HXWZ2_DATA
						},
						{
							id: roles[1].roleid,
							loadType: roles[1].abn == "1" ? ABN_DATA : HXWZ2_DATA
						}
					],
					player1: roles[0].roleid,
					player2: roles[1].roleid
				});
				SceneManager.getInstance().replaceScene(gameWorld);
			}
			this.releaseScene();
			SceneManager.getInstance().replaceScene(view);
		}

		this.btn_pvp2.clickEvent = () -> {
			this.releaseScene();
			ModeManage.start(PK1V1Mode);
		}

		this.btn_study.clickEvent = () -> {
			this.releaseScene();
			ModeManage.start(PracticeArenaMode);
		}
	}
}
